 import geoJson from '../compones/china.json'
  import * as echarts from 'echarts'
  echarts.registerMap('china', geoJson);

var geoCoordMap = {},
      data = [],
      lineData = [];
   geoJson.features.forEach(function (item, index) {
      var name = item.properties.name,
         cp = item.properties.center;
      if (cp) {
         geoCoordMap[name] = cp; // 地区经纬度
         data.push({
            name: name,
            value: cp.concat(Math.round(Math.random() * 100))
         })
         if (name != "北京") {
            lineData.push([
               { name: '北京' },
               { name: name, value: Math.round(Math.random() * 100) }
            ])
         }
      }
   });

   var convertData = function (data) {
      var res = [];
      for (var i = 0; i < data.length; i++) {
         var geoCoord = geoCoordMap[data[i].name];
         if (geoCoord) {
            res.push({
               name: data[i].name,
               value: geoCoord.concat(data[i].value),
            });
         }
      }
      return res;
   };
   var convertDataLine = function (data) {
      var res = [];
      for (var i = 0; i < data.length; i++) {
         var dataItem = data[i];
         var fromCoord = geoCoordMap[dataItem[0].name];
         var toCoord = geoCoordMap[dataItem[1].name];
         if (fromCoord && toCoord) {
            res.push({
               fromName: dataItem[0].name,
               toName: dataItem[1].name,
               coords: [fromCoord, toCoord]
            });
         }
      }
      return res;
   };

 export const   option5 = {
      visualMap: {
         show: false,
         min: 0,
         max: 100,
         left: 'left',
         top: 'bottom',
         text: ['高', '低'], // 文本，默认为数值文本
         calculable: true,
         seriesIndex: [1],
         inRange: {
            color: ['#004693'] // 蓝绿
         }
      },
      geo: {
         show: true,
         map: 'china',
         roam: true,
         zoom: 1.25,
         label: {
            normal: {
               show: false
            },
            emphasis: {
               show: false,
            }
         },
         itemStyle: {
            normal: {
               areaColor: '#031525',
               borderWidth: 1,
               borderColor: '#00CFFC',
            },
            emphasis: {
               areaColor: '#2B91B7',
            }
         }
      },
      series: [
         {
            name: '散点',
            type: 'scatter',
            coordinateSystem: 'geo',
            data: convertData(data),
            symbolSize: 5,
            // symbolSize: function(val) {
            //     return val[2] / 10;
            // },
            label: {
               normal: {
                  formatter: '{b}',
                  position: 'bottom',
                  show: true
               },
               emphasis: {
                  show: true
               }
            },
            itemStyle: {
               normal: {
                  color: 'red'
               }
            }
         },
         {
            type: 'map',
            map: 'china',
            geoIndex: 0,
            roam: true,
            aspectScale: 0.75, //长宽比
            showLegendSymbol: false, // 存在legend时显示
            label: {
               normal: {
                  show: true
               },
               emphasis: {
                  show: false,
                  textStyle: {
                     color: '#fff'
                  }
               }
            },
            itemStyle: {
               normal: {
                  areaColor: '#031525',
                  borderColor: '#3B5077'
               },
               emphasis: {
                  areaColor: '#2B91B7'
               }
            },
            animation: false,
            data: data
         },
         {
            name: '点',
            type: 'scatter',
            coordinateSystem: 'geo',
            symbol: 'pin', //气泡
            symbolSize: function (val) {
               return 30
            },
            label: {
               show: true,
               formatter: function (parm) {
                  return parm.value[4]
               },
               textStyle: {
                  color: '#fff'
               }
            },
            itemStyle: {
               color: '#F62157' //标志颜色
            },
            zlevel: 6,
            data: convertData(data)
         },
      ]
   };
